package com.ttg.common.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;

/**
 * @author cy
 * @version 1.0
 * @Description
 * @date 2025/4/18 17:43
 */
public class ListBeanUtil extends BeanUtils {

    /**
     * List<Object> 之間複製
     * @param sources
     * @param target
     * @param <S>
     * @param <T>
     * @return
     */
    public static <S,T> List<T> copyListProperties(List<S> sources, Supplier<T> target){
        if(Objects.isNull(sources)){
            return null;
        }
        List<T> list = new ArrayList<>();
        for(S source:sources){
            T t = target.get();
            copyProperties(source,t);
            list.add(t);
        }
        return list;
    }

}
